package huoye.shops.guidance;

import android.app.LauncherActivity;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;


import com.codeideology.android.utils.StringUtils;

import java.util.Timer;
import java.util.TimerTask;

import huoye.shops.MainActivity;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.UserManager;
import huoye.shops.huoye.user.activity.LoginActivity;
import huoye.shops.huoye.user.activity.SelectCityActivity;
import huoye.shops.huoye.user.activity.SelectNewActivity;
import huoye.shops.sp.SharedPreferencesUtil;

public class LaunchActivity extends BaseActivity {


    @Override
    protected int getContentViewId() {
        return R.layout.acitvity_launch;
    }
    private Intent localIntent;
    @Override
    protected void initView(@Nullable Bundle bundle) {
        isFirstStart();
        Timer timer=new Timer();
        TimerTask tast=new TimerTask() {
            @Override
            public void run(){
                startActivity(localIntent);
                LaunchActivity.this.finish();
            }
        };
        timer.schedule(tast,2000);
    }


    private void isFirstStart(){
        // 是否第一次安装
        SharedPreferencesUtil shared=new SharedPreferencesUtil(this, APIUrls.CONFIG);
        boolean isFirstStart = shared.getBoolean( APIUrls.IS_FIRST_START);
        if (!isFirstStart) {
            localIntent= new Intent(this, GuideActivity.class);
            shared.putBoolean(APIUrls.IS_FIRST_START,true);
        } else {
            if(StringUtils.isNotEmpty(UserManager.getInstance().getCity())){
                localIntent = new Intent(this, LoginActivity.class);
            }else {
                localIntent = new Intent(this,SelectNewActivity.class);

            }

        }

    }


}
